package com.xiaolin.admin.controller;

import com.github.pagehelper.PageInfo;
import com.xiaolin.admin.annotations.HasApi;
import com.xiaolin.admin.constants.ApiPermConstant;
import com.xiaolin.admin.model.dto.SysUserView;
import com.xiaolin.admin.model.entity.SysUser;
import com.xiaolin.admin.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiaolin
 * @description 描述
 * @since 2024/7/12
 */
@Api("用户资源")
@RestController
@RequestMapping("/user")
public class SysUserController {

    @Autowired
    private SysUserService userService;

    @HasApi({ApiPermConstant.COMMON_PERM})
    @ApiOperation("获取所有用户")
    @PostMapping("/getList")
    public List<SysUserView> getUserList(@RequestBody SysUser user) {
        return userService.getUserList(user);
    }

    @HasApi({"user:home"})
    @ApiOperation("获取用户列表")
    @PostMapping("/getPage/{page}/{pageSize}")
    public PageInfo<SysUserView> getUserPage(@PathVariable Integer page,
                                             @PathVariable Integer pageSize,
                                             @RequestBody SysUser user) {
        return userService.getUserPage(page, pageSize, user);
    }

    @HasApi({"user:add"})
    @ApiOperation("添加用户")
    @PostMapping("/add")
    public boolean addUser(@RequestBody SysUser user) {
        return userService.addUser(user);
    }

    @HasApi({"user:get"})
    @ApiOperation("获取用户")
    @PostMapping("/get/{id}")
    public SysUser getUser(@PathVariable("id") Integer id) {
        return userService.getUser(id);
    }

    @HasApi({"user:update"})
    @ApiOperation("修改用户")
    @PostMapping("/update")
    public boolean updateUser(@RequestBody SysUser user) {
        return userService.updateUser(user);
    }

    @HasApi({"user:enable"})
    @ApiOperation("启用禁用")
    @PostMapping("/status/{id}/{status}")
    public boolean status(@PathVariable Integer id, @PathVariable String status) {
        return userService.status(id, status);
    }

    @HasApi({"user:del"})
    @ApiOperation("删除用户")
    @PostMapping("/delete/{id}")
    public boolean deleteUser(@PathVariable Integer id) {
        return userService.deleteUser(id);
    }
}
